package work20241226;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zdl
 * @date 2024/12/26
 */
class MyThreadFirst implements Runnable{
    @Override
    public void run() {
        for (int i = 1; i < 101; i++) {
            System.out.println(Thread.currentThread().getName()+"线程执行打印:"+i);
        }
    }
}
class MyThreadSecond implements Runnable{
    @Override
    public void run() {
        for (int i = 1; i < 101; i++) {
            System.out.println(Thread.currentThread().getName()+"线程执行打印:"+i);
        }
    }
}
public class Demo1_1 {
    public static void main(String[] args) throws InterruptedException {
       // 1. 创建两个线程，输出1到100的数字。
        //第一种方式
        new Thread(new MyThreadFirst()).start();
        new Thread(new MyThreadSecond()).start();
        Thread.sleep(10000);

        //第二种方式  线程池
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(2, 6, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(2));
        poolExecutor.execute(new MyThreadFirst());
        poolExecutor.execute(new MyThreadSecond());
    }
}
